home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
L' Effet Pommier 3
/
L'Effet Pommier - Volume 03.iso
/
Programmation
/
PlayerPRO 4.5.1 Dev.Kit
/
Plug-Ins
/
Filters Plugs
/
Echo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-10-08
|
5KB
|
210 lines
/* Echo */
/* v 0.3 */
/* 1995 by Liane */
// Usage:
// Simulates an echo.
// You can set the timing (ms), which is computed
// for a F#5.
// Works on the selected part or all the waveform
// if there is no selection.
#include <Dialogs.h>
#include "MAD.h"
#include "PPPlug.h"
#if defined(powerc) || defined(__powerc)
enum {
PlayerPROPlug = kCStackBased
| RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( sData*)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( long)))
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
| STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoPlug*)))
};
ProcInfoType __procinfo = PlayerPROPlug;
#else
#include <A4Stuff.h>
#endif
#define tdelay 3
#define tstrength 4
#define enclosure 9
GDHandle TheGDevice:0xCC8;
void AutoPosition( DialogPtr aDia)
{
Point Position, mouse;
Rect ViewRect;
short XSize = (aDia->portRect.right - aDia->portRect.left), YSize = (aDia->portRect.bottom - aDia->portRect.top);
GetMouse( &mouse);
LocalToGlobal( &mouse);
SetRect( &ViewRect, (*TheGDevice)->gdRect.left + 8, (*TheGDevice)->gdRect.top + 43,
(*TheGDevice)->gdRect.right - 8, (*TheGDevice)->gdRect.bottom - 8);
Position.h = mouse.h - XSize/2;
if( Position.h + XSize >= ViewRect.right) Position.h = ViewRect.right - XSize;
else if( Position.h <= ViewRect.left) Position.h = ViewRect.left;
Position.v = mouse.v - YSize/2;
if( Position.v + YSize >= ViewRect.bottom) Position.v = ViewRect.bottom - YSize;
else if( Position.v <= ViewRect.top) Position.v = ViewRect.top;
MoveWindow( aDia, Position.h, Position.v, false);
ShowWindow( aDia);
}
void raiseRect (Rect theRect)
{
ForeColor(whiteColor);
MoveTo(theRect.left,theRect.bottom);
LineTo(theRect.left,theRect.top);
LineTo(theRect.right,theRect.top);
ForeColor(blackColor);
LineTo(theRect.right,theRect.bottom);
LineTo(theRect.left,theRect.bottom);
}
#define timeConvert 22254 //┼22KHZ
pascal void xRectProc (WindowPtr theWindow,
short theItem)
{
short iType;
Handle iHandle;
Rect iRect;
GetDItem(theWindow,theItem,&iType,&iHandle,&iRect);
raiseRect( iRect);
}
Boolean getParams ( short dlgID, long *p1, long *p2, PPInfoPlug *thePPInfoPlug)
{
DialogPtr theDialog;
Boolean theResult = false;
theDialog = GetNewDialog(dlgID,nil,(WindowPtr)-1);
if (theDialog) {
short iType, itemHit;
Handle iHandle;
Rect iRect;
Str255 textStr;
SetPort( theDialog);
AutoPosition( theDialog);
GetDItem(theDialog,enclosure,&iType,&iHandle,&iRect);
SetDItem(theDialog,enclosure,iType,(Handle)xRectProc,&iRect);
GetDItem(theDialog,tdelay,&iType,&iHandle,&iRect);
NumToString(*p1,textStr);
SetIText(iHandle,textStr);
GetDItem(theDialog,tstrength,&iType,&iHandle,&iRect);
NumToString(*p2,textStr);
SetIText(iHandle,textStr);
SelIText(theDialog,tdelay,0,32767);
// SetDialogDefaultItem(theDialog,1);
do
{
ModalDialog( (ModalFilterProcPtr) thePPInfoPlug->MyDlgFilterUPP, &itemHit);
}
while ((itemHit != ok) && (itemHit != cancel));
if (itemHit == ok)
{
theResult = true;
GetDItem(theDialog,tdelay,&iType,&iHandle,&iRect);
GetIText(iHandle,textStr);
StringToNum(textStr,p1);
GetDItem(theDialog,tstrength,&iType,&iHandle,&iRect);
GetIText(iHandle,textStr);
StringToNum(textStr,p2);
}
DisposDialog(theDialog);
}
return theResult;
}
int checkMax (int v)
{
if( v >= 127) return 127;
else if( v <= -127 ) return -127;
else return v;
}
OSErr main( sData *theData,
long SelectionStart,
long SelectionEnd,
PPInfoPlug *thePPInfoPlug)
{
long i, length,
temp1, temp2,
pDelay = 250, pStrength = 50;
if (getParams (5000, &pDelay, &pStrength, thePPInfoPlug))
{
if (SelectionStart == SelectionEnd)
{
SelectionStart = 0;
SelectionEnd = theData->size;
}
length = SelectionEnd - SelectionStart - 1;
pDelay = (pDelay * timeConvert) / 1000; //convert ms to samples
switch( theData->amp)
{
case 8:
{
Ptr orgPtr = (theData->data) + SelectionStart, destPtr = orgPtr + pDelay;
for( i = 0; i < (length - pDelay); i++)
{
temp1 = *orgPtr++;
temp1 = (pStrength * temp1) / 100;
temp2 = *destPtr;
temp1 += temp2;
if( temp1 >= 127) temp1 = 127; // overflow ?
else if( temp1 <= -128 ) temp1 = -128;
*destPtr++ = temp1;
}
}
break;
case 16:
{
short *orgPtr = (short*) theData->data + (SelectionStart / 2),
*destPtr = orgPtr + pDelay;
for( i = 0; i < length / 2 - pDelay; i++)
{
temp1 = *orgPtr++;
temp1 = (pStrength * temp1) / 100;
temp2 = *destPtr;
temp1 += temp2;
if( temp1 >= (short)0x7FFF) temp1 = 0x7FFF; // overflow ?
else if( temp1 <= (short)0x8000 ) temp1 = (short)0x8000;
*destPtr++ = temp1;
}
}
break;
}
}
return noErr;
}